package com.pk.platform.business.common.web;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.common.service.IChildService;
import com.pk.platform.business.common.service.IClaService;
import com.pk.platform.business.common.service.IKindergartenService;
import com.pk.platform.business.common.vo.ChildVO;
import com.pk.platform.business.common.vo.ClaVO;
import com.pk.platform.business.core.web.GenericAction;
import com.pk.platform.domain.common.Child;
import com.pk.platform.domain.common.Cla;
import com.pk.platform.domain.common.Kindergarten;
import com.pk.platform.domain.privilege.User;
import com.pk.platform.util.DateConverter;
import com.pk.platform.util.constant.PrivilegeConstant;

public class ChildAction extends GenericAction {

	private IChildService childService;
	
	private IClaService claService;
	
	private ChildVO childvo = new ChildVO();
	
	private ClaVO clavo = new ClaVO();
	
	private Child child = new Child();
	
	private List<Cla> classList = new ArrayList<Cla>();
	
	private boolean delFlag = false;
	
	private String childIds;
	
	private IKindergartenService kindergartenService;
	
	private InputStream excelStream;
	
	public String childrenManage()
	{
		classList = claService.queryClassList(kindergartenId);
		childvo.setKindergartenId(kindergartenId);
		lp = childService.queryChildren(childvo, pager);
		//查看或修改
		operateChn = PrivilegeConstant.getOperate(PrivilegeConstant.UPDATE_CHILD);
		return SUCCESS;
	}
	
	public String toAddChild()
	{
		classList = claService.queryClassList(kindergartenId);
		return SUCCESS;
	}
	
	public String addChild()
	{
		Kindergarten k = kindergartenService.queryKindergartenById(kindergartenId);
		child.setKindergarten(k);
		message = childService.addChild(child);
		return SUCCESS;
	}
	
	public String toUpdateChild()
	{
		child = childService.queryChildById(child.getId());
		classList = claService.queryClassList(kindergartenId);
		return SUCCESS;
	}
	
	public String updateChild()
	{
		message = childService.updateChild(child);
		return SUCCESS;
	}
	
	public String delChild()
	{
		delFlag = childService.delChild(child.getId());
		return SUCCESS;
	}
	
	public String toBatchUpdate()
	{
		classList = claService.queryClassList(kindergartenId);
		return SUCCESS;
	}

	public String batchUpdateClass()
	{
		childService.batchUpdateClass(childIds, child.getCla().getId());
		return SUCCESS;
	}
	
	public String batchUpdateStatus()
	{
		childService.batchUpdateStatus(childIds, child.getStatus());
		return SUCCESS;
	}
	
	public String toSelectChild()
	{
		classList = claService.queryClassList(kindergartenId);
		childvo.setKindergartenId(kindergartenId);
		lp = childService.queryChildren(childvo, pager);
		return SUCCESS;
	}
	
	public String queryPaySituationByThisMonth()
	{
		today = DateConverter.getToday();
		classList = claService.queryClassList(kindergartenId);
		childvo.setKindergartenId(kindergartenId);
		lp = childService.queryPaySituationByThisMonth(childvo, pager);
		return SUCCESS;
	}
	
	public String exportChildren()
	{
		childvo.setKindergartenId(kindergartenId);
		excelStream = childService.exportChildren(childvo);
		return FILE;
	}

	public IChildService getChildService() {
		return childService;
	}

	public void setChildService(IChildService childService) {
		this.childService = childService;
	}

	public ChildVO getChildvo() {
		return childvo;
	}

	public void setChildvo(ChildVO childvo) {
		this.childvo = childvo;
	}

	public Child getChild() {
		return child;
	}

	public void setChild(Child child) {
		this.child = child;
	}

	public ClaVO getClavo() {
		return clavo;
	}

	public void setClavo(ClaVO clavo) {
		this.clavo = clavo;
	}

	public List<Cla> getClassList() {
		return classList;
	}

	public void setClassList(List<Cla> classList) {
		this.classList = classList;
	}

	public IClaService getClaService() {
		return claService;
	}

	public void setClaService(IClaService claService) {
		this.claService = claService;
	}

	public boolean isDelFlag() {
		return delFlag;
	}

	public void setDelFlag(boolean delFlag) {
		this.delFlag = delFlag;
	}

	public String getChildIds() {
		return childIds;
	}

	public void setChildIds(String childIds) {
		this.childIds = childIds;
	}

	public IKindergartenService getKindergartenService() {
		return kindergartenService;
	}

	public void setKindergartenService(IKindergartenService kindergartenService) {
		this.kindergartenService = kindergartenService;
	}

	public InputStream getExcelStream() {
		return excelStream;
	}

	public void setExcelStream(InputStream excelStream) {
		this.excelStream = excelStream;
	}
	
}
